/*
 * Copyright (C) 2004-2006  Autodesk, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of version 2.1 of the GNU Lesser
 * General Public License as published by the Free Software Foundation.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#include "Pch.h"
#include "ConnectTests.h"

CPPUNIT_TEST_SUITE_REGISTRATION (ConnectTests);
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION (ConnectTests, "ConnectTests");


ConnectTests::ConnectTests (void)
{
}

ConnectTests::~ConnectTests (void)
{
}

void ConnectTests::TestConnection(FdoString* connString, bool expectedExc)
{
    try
    {
        FdoPtr<FdoIConnection> connection = CMSTests::GetConnection ();

        connection->SetConnectionString(connString);
        FdoConnectionState state = connection->Open ();
        connection->Close ();
    }
    catch (FdoException* e)
    {
        if (!expectedExc)
            fail(e);
        else
        {
            FdoStringP txt = e->GetExceptionMessage();
            e->Release();
            printf ("\n Expected exception: %s \n", (const char*)txt);
        }
    }
}

void ConnectTests::TestGoogle()
{
    FdoStringP connString = FdoStringP(L"FeatureServer=") + UnitTestGlobals::CMSGoogleServiceName + L";APIKey=ABQIAAAAa90S5XRpq6shaMXIF3zUzRTVhk_FawdprkxQ7rY9h5v2o213HxQ1T-519seO5TvavyGYMXXO_zwzOQ";
    TestConnection(connString);
}

void ConnectTests::TestBing()
{
    FdoStringP connString = FdoStringP(L"FeatureServer=") + UnitTestGlobals::CMSBingServiceName;
    TestConnection(connString);
}

void ConnectTests::TestYahoo()
{
    FdoStringP connString = FdoStringP(L"FeatureServer=") + UnitTestGlobals::CMSYahooServiceName;
    TestConnection(connString);
}

void ConnectTests::TestInvalid()
{
    FdoStringP connString = L"FeatureServer=http://maps.google.com/maps/invalid/api/staticmap?;APIKey=ABQIAAAAa90S5XRpq6shaMXIF3zUzRTVhk_FawdprkxQ7rY9h5v2o213HxQ1T-519seO5TvavyGYMXXO_zwzOQ";
    TestConnection(connString, /*expectedExc=*/true);
}


